import wx
from Node import Node
from Disk import Disk
from Log import Log
from User import User
from XML_File import XML_File

import wx
import wx.lib.mixins.listctrl  as  listmix

 
 
class EditableListCtrl(wx.ListCtrl, listmix.TextEditMixin):
    ''' TextEditMixin allows any column to be edited. '''
 
    #----------------------------------------------------------------------
    def __init__(self, parent, ID=wx.ID_ANY, pos=wx.DefaultPosition,
                 size=wx.DefaultSize, style=0):
        """Constructor"""
        wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
        listmix.TextEditMixin.__init__(self) 
 
 
 
 
 
########################################################################
class MyForm(wx.Frame):
 
    #----------------------------------------------------------------------
    def __init__(self,xmlPropList):
        
      
        
        
        
        wx.Frame.__init__(self, None, wx.ID_ANY, "EMC Greenplum HD Config Manager",size=(1200,600))
        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)
        self.index = 0
        self.Center()
        self.list_ctrl = EditableListCtrl(panel, size=(500,500),
                         style=wx.LC_REPORT
                         |wx.BORDER_SUNKEN
                         )
        
        self.list_ctrl.InsertColumn(0, 'Name')
        self.list_ctrl.InsertColumn(1, 'Value')
        self.list_ctrl.SetColumnWidth(0,350)
        self.list_ctrl.SetColumnWidth(1,750)
        
        rowIndex = 0
        for prop in xmlPropList:
           
            self.list_ctrl.InsertStringItem(rowIndex,str(prop['name']))
            self.list_ctrl.SetStringItem(rowIndex,1,str(prop['value']))
            if rowIndex % 2:
                self.list_ctrl.SetItemBackgroundColour(rowIndex, "white")
            else:
                self.list_ctrl.SetItemBackgroundColour(rowIndex, "yellow")
            rowIndex += 1        
        
        btn = wx.Button(panel, label="Add Line")
        btn.Bind(wx.EVT_BUTTON, self.add_line)
 
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
        sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
        panel.SetSizer(sizer)
 
    #----------------------------------------------------------------------
    def add_line(self, event):
        
        line = "Line %s" % self.index
        self.list_ctrl.InsertStringItem(self.index, line)
        self.list_ctrl.SetStringItem(self.index, 1, "01/19/2010")
        self.list_ctrl.SetStringItem(self.index, 2, "USA")
        self.index += 1
 
#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
    
    Roles = []
    Nodes = []
    Users = []
    adminUser = "root"
    adminPW  = "P@ssw0rd"
    Logs = Log()
    Users.append(User("root","P@ssw0rd","r","Adminstrative User"))
    coreSite = XML_File("mapred-site.xml",Logs,Nodes,Users)
    xmlPropList = coreSite.getProperties()
    app = wx.App(False)
    frame = MyForm(xmlPropList)
    frame.Show()
    app.MainLoop()

